<template>
	<view>	
		<view class="u-flex user-box u-p-l-30 u-p-r-20 u-p-b-30">
			<!-- #ifdef MP-WEIXIN -->
			<view class="u-m-r-10" style="margin: 0 auto!important;margin-top: 35px!important;text-align: center;">
				
				<button open-type="getUserInfo"	 @getuserinfo="login" v-if="!isLogin">
					<u-avatar  :src="pic" size="140"></u-avatar>
					<view >
						点击登录
					</view>
				</button>
				<view v-else class="userAvatarUrl">
					<open-data type="userAvatarUrl" v-if="!isLogin.avatar"></open-data>
					<u-avatar  :src="isLogin.avatar" size="140"></u-avatar>
				</view>
			</view>
			<!-- #endif -->
			
			<!-- h5端和app端 -->
			<!-- #ifdef H5 || APP-PLUS -->
			<view class="u-m-r-10" style="margin: 0 auto!important;margin-top: 35px!important;text-align: center;">
				<view  class="userAsvatarUrl" v-if="isLogin">
					<u-avatar v-if="isLogin.avatar" :src="'http://www.travelapi.com/storage/' + isLogin.avatar" size="140"></u-avatar>
					<u-avatar v-else  :src="isLogin.avatar" size="140"></u-avatar>
				</view>
			</view>
			<!-- #endif -->
		</view>
		
		<view class="u-m-t-20">
			<u-cell-group>
				<u-cell-item icon="rmb-circle" @click="userinfo" title="个人资料"></u-cell-item>
			</u-cell-group>
		</view>
		
		<view class="u-m-t-20">
			<u-cell-group>
				<u-cell-item icon="star" title="我的订单"></u-cell-item>
				<u-cell-item icon="photo" title="相册"></u-cell-item>
				<u-cell-item icon="coupon" title="卡券"></u-cell-item>
				<u-cell-item icon="heart" title="关注"></u-cell-item>
			</u-cell-group>
		</view>
		
		<view class="u-m-t-20">
			<u-cell-group>
				<u-cell-item icon="setting" title="退出"></u-cell-item>
			</u-cell-group>
		</view>
	</view>
</template>

<script>
	export default {
		data() {
			return {
				isLogin:uni.getStorageSync("userkey")
			}
		},
		methods:{
			 login(e){
				 var that = this
				if(e.detail.errMsg == "getUserInfo:ok"){
					uni.login({
						provider:"weixin",
						async success(e) {
							let login =  await that.$u.proxy.user.login({
								code:e.code
							})
							if(login.success){
								uni.setStorageSync("userkey",login.data)
								
								that.$u.route({
									type:"reLaunch",
									url: 'pages/my/my',
								})							
							}else if(login.data.code == "202"){
								
								that.$u.route({
									type:"navigateTo",
									url:"user/binduser/binduser"
								})
							}

						}
					})
				}

			},
			userinfo(){
				this.$u.route({
					type:"navigateTo",
					url:"user/userinfo/userinfo"
				})
			}
		}
	} 
</script>  
 
<style lang="scss">
button{
	padding: 0;
	line-height: 16px;
	background:none;
	border: none;
	font-size: 26rpx;
	background-color: transparent!important;
}
button::after{
	width: auto;
	height: auto;
	border: none;
}
.userAvatarUrl{
	border-radius: 50%;
	overflow: hidden;
	width: 200rpx;
	height: 200rpx;
}
open-data{
	width: 100%;
	height: 100%;
}
</style>